package com.zxd.streams;

import java.util.*;
import java.util.stream.Stream;

/**
 * ClassName:MyStream
 * Package:com.zxd.streams
 *
 * @Date:2023/9/24 20:17
 * @Author:zxde
 */

/**
 * stream的三个阶段： 生成流 ， 过滤流 ， 收集流
 * Collection类，获取stream，.stream()即可
 */
public class GetStream {
    public static void main(String[] args) {
        //list获取Stream、
        List<String> list = new ArrayList<>();
        List<String> list1 = new ArrayList<>();
        List<String> list2 = new ArrayList<>();
        List<String> list3 = new ArrayList<>();
        List<String> list4 = new ArrayList<>();
        Collections.addAll(list, "张三", "李四", "张三丰", "里斯怪", "vae");
        Collections.addAll(list1, "张三1", "李四1", "张三丰1", "里斯怪1", "vae1");
        Collections.addAll(list2, "张三2", "李四2", "张三丰2", "里斯怪2", "vae2");
        Collections.addAll(list3, "张三3", "李四3", "张三丰3", "里斯怪3", "vae3");
        Collections.addAll(list4, "张三4", "李四4", "张三丰4", "里斯怪4", "vae4");
        list.stream().filter(s -> s.contains("三")).filter(s -> s.length() == 2).forEach(System.out::println);
        System.out.println("---------------------------");

        //Map获取stream
        Map<String, List<String>> map = new HashMap<>();
        map.put("elm", list);
        map.put("elm2", list1);
        map.put("elm3", list2);
        map.put("elm4", list3);
        map.put("elm5", list4);

        map.entrySet().stream().filter(stringListEntry -> stringListEntry.getKey().contains("elm2")).forEach(stringListEntry -> {
            System.out.println("key=" + stringListEntry.getKey());
            System.out.println("value=" + stringListEntry.getValue());
        });

        System.out.println("---------------------------");
        String[] strings = new String[]{"张三", "李四", "张三丰", "里斯怪", "vae"};
        Arrays.stream(strings).filter(str->str.length()==3).forEach(System.out::println);

        System.out.println("---------------------------");
        Stream.of(strings).filter(str->str.length()==3).forEach(System.out::println);
    }
}
